package com.bwie.controller;

import com.bwie.pojo.Prod;
import com.bwie.service.ProdService;
import com.bwie.utils.R;
import com.bwie.utils.Result;
import com.bwie.vo.AttaVo;
import com.bwie.vo.PageInfoVo;
import com.bwie.vo.ProdPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: TaoShiHao
 * @Date: 2025/5/26 21:06
 * @Description:
 **/
@RestController
@RequestMapping("/shop/prod")
@Api(tags = "商品管理")
public class ProdController {

    @Autowired
    ProdService prodService;

    @PostMapping("/getProdList")
    @ApiOperation(value = "分页获取商品列表")
    public Result getProdList(@RequestBody ProdPageVo prodPageVo){
        return prodService.getProdList(prodPageVo);
    }

    @PostMapping("/addProd")
    @ApiOperation(value = "添加商品")
    public Result addProd(@RequestBody @Validated Prod prod, BindingResult result){
        if(result.hasErrors()){
            return Result.error().setMsg(result.getFieldError().getDefaultMessage());
        }
        return  prodService.addProd(prod);
    }
    @PostMapping("/deleteAllProd")
    @ApiOperation(value = "批量删除商品")
    public Result deleteAllProd(@RequestBody List<Prod> prodList){
        return  prodService.deleteAllProd(prodList);
    }
    @PostMapping("/addProdAtta")
    @ApiOperation(value = "添加商品附件")
    public Result addProdAtta(@RequestBody AttaVo attaVo){
        return prodService.addProdAtta(attaVo);
    }
}
